//
//  HLWaybillBottomView.m
//  zhuanxian
//
//  Created by zhaoliang chen on 2017/11/17.
//  Copyright © 2017年 huiling. All rights reserved.
//

#import "HLWaybillBottomView.h"

@implementation HLWaybillBottomView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.borderColor = [UIColor grayColor].CGColor;
        self.layer.borderWidth = 1;
        
        UIView* tempView = nil;
        for (int i=0; i<3; i++) {
            UIView* view = [[UIView alloc]initWithFrame:CGRectZero];
            [self addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                if (tempView) {
                    make.left.mas_equalTo(tempView.mas_right);
                } else {
                    make.left.mas_equalTo(0);
                }
                make.top.bottom.mas_equalTo(self);
                make.width.mas_equalTo(self.mas_width).multipliedBy(1.0/3);
            }];
            
            UILabel* label = [self createLabel];
            [view addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.mas_equalTo(view);
                make.left.mas_equalTo(3);
            }];
            
            if (i==0) {
                label.text = @"总笔数:";
                [view addSubview:self.labelTotalCount];
                [self.labelTotalCount mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(label.mas_right);
                    make.bottom.mas_equalTo(label);
                }];
            } else if (i==1) {
                label.text = @"总运费:";
                [view addSubview:self.labelFreight];
                [self.labelFreight mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(label.mas_right);
                    make.bottom.mas_equalTo(label);
                }];
            } else {
                label.text = @"总代收:";
                [view addSubview:self.labelCollection];
                [self.labelCollection mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(label.mas_right);
                    make.bottom.mas_equalTo(label);
                }];
            }
            
            tempView = view;
        }
        
        UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickBottomView:)];
        [self addGestureRecognizer:tap];
    }
    return self;
}

- (void)onClickBottomView:(UITapGestureRecognizer*)sender {
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:[NSString stringWithFormat:@"总笔数:%@\n总运费:%@\n总代收%@",self.labelTotalCount.text,self.labelFreight.text,self.labelCollection.text] preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:cancelAction];
    [self.zl_viewController presentViewController:alert animated:YES completion:nil];
}

- (UILabel*)createLabel {
    UILabel* label = [[UILabel alloc]init];
    label.font = [UIFont systemFontOfSize:10];
    return label;
}

- (UILabel*)labelTotalCount {
    if (!_labelTotalCount) {
        _labelTotalCount = [[UILabel alloc]init];
        _labelTotalCount.textColor = [UIColor orangeColor];
        _labelTotalCount.font = [UIFont systemFontOfSize:15];
    }
    return _labelTotalCount;
}

- (UILabel*)labelFreight {
    if (!_labelFreight) {
        _labelFreight = [[UILabel alloc]init];
        _labelFreight.textColor = MainColor;
        _labelFreight.font = [UIFont systemFontOfSize:15];
    }
    return _labelFreight;
}

- (UILabel*)labelCollection {
    if (!_labelCollection) {
        _labelCollection = [[UILabel alloc]init];
        _labelCollection.textColor = MainColor;
        _labelCollection.font = [UIFont systemFontOfSize:15];
    }
    return _labelCollection;
}

@end
